

/**
 * https://leetcode-cn.com/problems/merge-two-binary-trees/
 * 合并二叉树
 * @param root1 
 * @param root2 
 */
const mergeTrees = (root1: TreeNode | null, root2: TreeNode | null): TreeNode | null => {
    if (root1 == null && root2 === null) return null
    if (root1 === null) return root2;
    if (root2 === null) return root1;

    // 根节点
    let newRoot = new TreeNode(root1.val + root2.val)

    // 合并左子树
    newRoot.left = mergeTrees(root1.left, root2.left)

    // 合并右子树
    newRoot.right = mergeTrees(root1.right, root2.right)

    return newRoot;
};
